////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011-2012 www.iflytek.com. All Rights Reserved.
//  This software for customer relationship management system, developed by Noo team.
//  Software code and design for the team, copy rights reserved.
////////////////////////////////////////////////////////////////////////////////

package com.iflytek.ci.cums.service.impl;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * <p>
 * 系统加密方案.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 2012-10-25 9:52 PM
 * @since JDK 1.5
 */
public class EncryptionPassword {

	/**
	 * encryption password
	 *
	 * @param password password
	 * @return encryption string
	 */
	public static String encryption(String password) {
		//plaintext with base64
		String base64 = base64(password);
		//add  encryption be confused string.
		base64 += "cdms";
		//sha_1 value
		return sha_1(base64);
	}

	/**
	 * sha-1 encrption base64 chars.
	 *
	 * @param base64 base64 char
	 * @return sha-1
	 */
	private static String sha_1(String base64) {
		return DigestUtils.sha1Hex(base64);
	}

	/**
	 * base64 string.
	 *
	 * @param password password
	 * @return base64 string
	 */
	private static String base64(String password) {
		return Base64.encodeBase64String(password.getBytes());
	}
}
